package sysAuth

import sysUtil.ResultCode
import sysUtil.ResultJson
import xdInterface.XdControllerInterface

class OperationController implements XdControllerInterface{

    def authUtilsService

    def index() {query()}

    @Override
    def delete() {
        del()
    }
    @Override
    def detail() {
        return null
    }

    @Override
    def del() {
        return null
    }

    @Override
    def edit() {
        return null
    }

    @Override
    def save() {
        return null
    }

    @Override
    def update() {
        def result = ResultJson.resultJson()
        try {

            def data = authUtilsService.updateOption(params)
            result.put(ResultJson.CODE.name, data.code)
            result.put(ResultJson.MSG.name, data.message)
        } catch (Exception e) {
            result.put(ResultJson.CODE.name, ResultCode.QUERY_ERROR.code)
            result.put(ResultJson.MSG.name, ResultCode.QUERY_ERROR.message)
            e.printStackTrace()
        } finally {
            render result.toString()
        }
    }

    @Override
    def add() {
        def result = ResultJson.resultJson()
        try {

            def data = authUtilsService.addOption(params)
            result.put(ResultJson.CODE.name, data.code)
            result.put(ResultJson.MSG.name, data.message)
        } catch (Exception e) {
            result.put(ResultJson.CODE.name, ResultCode.QUERY_ERROR.code)
            result.put(ResultJson.MSG.name, ResultCode.QUERY_ERROR.message)
            e.printStackTrace()
        } finally {
            render result.toString()
        }
    }

    @Override
    def dowLoad() {
        return null
    }

    @Override
    def upLoad() {
        return null
    }

    @Override
    def query() {
        def result = ResultJson.resultJson()
        try {

            def list = authUtilsService.listOptionData()
            result.put(ResultJson.DATA.name,list)
            result.put(ResultJson.CODE.name, ResultCode.TABLE_DATA_SUCCESS.code)
            result.put(ResultJson.MSG.name, ResultCode.OPT_SUCCESS.message)
        } catch (Exception e) {
            result.put(ResultJson.CODE.name, ResultCode.QUERY_ERROR.code)
            result.put(ResultJson.MSG.name, ResultCode.QUERY_ERROR.message)
            e.printStackTrace()
        } finally {
            render result.toString()
        }
    }

    @Override
    def getOne() {
        return null
    }
}
